package com.tduck.cloud.dashboard.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.tduck.cloud.common.util.Result;
import com.tduck.cloud.dashboard.request.ChartDataRequest;
import com.tduck.cloud.dashboard.service.impl.DashboardChartDataService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 仪表盘图表
 * @author : tduck
 * @since  :  2022/11/09 11:01
 **/
@RestController
@RequiredArgsConstructor
@RequestMapping("/dashboard/chart")
public class DashboardChartController {

    private final DashboardChartDataService chartDataService;

    /**
     * 图表获取数据
     */
    @PostMapping("/data")
    public Result getChartData(@RequestBody ChartDataRequest request) {
        if (StrUtil.isBlank(request.getIndexName()) ||
                CollUtil.isEmpty(request.getIndex())) {
            return Result.success();
        }
        return Result.success(chartDataService.getChartData(request));
    }

}
